Milton Crash Data Analysis
[1]:
import pandas as pd
import folium
from IPython.display import HTML
import geopandas as gpd
from shapely.geometry import Point
import matplotlib.pyplot as plt
import contextily as ctx
import milton_maps as mm
import seaborn as sns
/Users/alexhasha/Library/Caches/pypoetry/virtualenvs/milton-maps-gfMaDXEA-py3.10/lib/python3.10/site-packages/geopandas/_compat.py:123: UserWarning: The Shapely GEOS version (3.10.3-CAPI-1.16.1) is incompatible with the GEOS version PyGEOS was compiled with (3.10.4-CAPI-1.16.2). Conversions between both will be slow.
warnings.warn(
[2]:
town_boundaries = gpd.read_file("../data/processed/town_boundaries.shp.zip").set_index("TOWN_ID")
milton_boundaries = town_boundaries[town_boundaries.TOWN.isin(["MILTON"])]
[3]:
crash_data = pd.read_excel("../data/raw/CrashDetails_cwzqv2fitj4m5ovin0xrkq11.xls", skiprows=6)
crash_data.shape
WARNING *** file size (3678144) not 512 + multiple of sector size (512)
[3]:
(4571, 28)
[4]:
crash_data.head(10)
[4]:
| RMV Crash Number | City Town Name | Crash Date | Crash Time | Crash Severity | Maximum Injury Severity Reported | Number of Vehicles | Total Nonfatal Injuries | Total Fatal Injuries | Manner of Collision | ... | Ambient Light | Weather Condition | At Roadway Intersection | Distance From Nearest Roadway Intersection | Distance From Nearest Milemarker | Distance From Nearest Exit | Distance From Nearest Landmark | Non Motorist Type | X Cooordinate | Y Cooordinate | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 4136317 | MILTON | 01-Jan-2016 | 2:50 AM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | Dark - lighted roadway | Clear | NaN | Rte 93 S / UNKNOWN | NaN | Exit 9 on Rte 93 S | NaN | NaN | 237954.181333 | 889568.707045 |
| 1 | 4138031 | MILTON | 03-Jan-2016 | 2:30 AM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | Dark - roadway not lighted | Cloudy | NaN | UNQUITY ROAD / HARLAND STREET | NaN | NaN | CAMP SAYRE | NaN | 233823.778861 | 887239.065913 |
| 2 | 4170301 | MILTON | 03-Jan-2016 | 3:08 AM | Property damage only (none injured) | No injury | 3.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | Dark - lighted roadway | Clear/Clear | REEDSDALE ROAD / THOMPSON LANE | REEDSDALE ROAD / THOMPSON LANE | NaN | NaN | NaN | NaN | 234704.583122 | 889639.264997 |
| 3 | 4170346 | MILTON | 03-Jan-2016 | 11:28 AM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Rear-end | ... | Daylight | Cloudy | NaN | 1249 RANDOLPH AVENUE Rte 28 | NaN | NaN | NaN | NaN | 235426.833031 | 886303.215857 |
| 4 | 4170384 | MILTON | 03-Jan-2016 | 6:47 PM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | Dark - lighted roadway | Clear/Clear | NaN | 1043 RANDOLPH AVENUE | NaN | NaN | NaN | NaN | 235455.851915 | 887025.734960 |
| 5 | 4170300 | MILTON | 04-Jan-2016 | 7:36 AM | Non-fatal injury | Non-fatal injury - Possible | 3.0 | 3.0 | 0.0 | Rear-end | ... | Daylight | Cloudy | NaN | 590 RANDOLPH AVENUE Rte 28 | NaN | NaN | NaN | NaN | 235554.657386 | 888798.446842 |
| 6 | 4172349 | MILTON | 05-Jan-2016 | 12:02 AM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | Dark - lighted roadway | Clear | RANDOLPH AVENUE / REEDSDALE ROAD | RANDOLPH AVENUE / REEDSDALE ROAD | NaN | NaN | NaN | NaN | 235553.115602 | 888768.223461 |
| 7 | 4170299 | MILTON | 05-Jan-2016 | 8:43 AM | Property damage only (none injured) | No injury | 3.0 | 0.0 | 0.0 | Rear-end | ... | Daylight | Clear | NaN | 384 CENTRAL AVENUE | NaN | NaN | NaN | NaN | 234574.482775 | 889931.291720 |
| 8 | 4172298 | MILTON | 05-Jan-2016 | 2:47 PM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | Daylight | Clear | BRUSH HILL ROAD / BLUE HILL AVENUE Rte SR138 S | BRUSH HILL ROAD / BLUE HILL AVENUE Rte SR138 S | NaN | NaN | NaN | NaN | 233466.280912 | 890649.454822 |
| 9 | 4172293 | MILTON | 06-Jan-2016 | 5:39 AM | Non-fatal injury | Non-fatal injury - Non-incapacitating | 2.0 | 2.0 | 0.0 | Rear-end | ... | Dark - lighted roadway | Clear | BLUE HILL AVENUE / DOLLAR LANE | BLUE HILL AVENUE / DOLLAR LANE | NaN | NaN | NaN | NaN | 231949.470671 | 886895.988963 |
10 rows × 28 columns
Data transformation notes:
Need to parse Crash Date + Crash Time into a datetime field.
Transform Crash Severity into a categorical variable.
Transform Manner of Collission into a categorical variable.
[5]:
print(f"{crash_data[crash_data['X Cooordinate'].isnull()].shape[0]} records are missing coordinates. We'll drop these for now.")
310 records are missing coordinates. We'll drop these for now.
[6]:
crash_data = crash_data[~crash_data['X Cooordinate'].isnull()]
[7]:
geometry = [Point(row['X Cooordinate'], row['Y Cooordinate']) for i, row in crash_data.iterrows()]
[8]:
crash_geodf = gpd.GeoDataFrame(data=crash_data, geometry=geometry, crs="EPSG:26986")
[ ]:
fig, ax = plt.subplots(1, figsize=(20,20))
ax = mm.plot_map(crash_geodf,
column="Maximum Injury Severity Reported",
categorical=True,
markersize=30,
alpha=0.75,
ax=ax
)
ctx.add_basemap(ax, crs="EPSG:26986")
Questions:
How to identify accidents along Randolph Avenue?
[10]:
injury_map = {
'No injury': 'No Injury',
'Non-fatal injury - Possible': 'Minor Injury',
'Non-fatal injury - Non-incapacitating': 'Minor Injury',
'Non-fatal injury - Incapacitating': "Major Injury",
'Not reported': "Unknown",
'Fatal injury (K)': "Fatal Injury",
'Unknown': "Unknown",
'Not Applicable': "No Injury",
'Deceased not caused by crash': "No Injury",
'No Apparent Injury (O)': "No Injury",
'Suspected Minor Injury (B)': "Minor Injury",
'Possible Injury (C)': "Minor Injury",
'Suspected Serious Injury (A)': "Major Injury",
}
crash_geodf['severity'] = crash_geodf['Maximum Injury Severity Reported'].fillna("Unknown").map(injury_map)
[11]:
colormap = {
"Unknown": "gray",
"No Injury": "blue",
"Minor Injury": "yellow",
"Major Injury": "orange",
"Fatal Injury": "red",
}
[12]:
crash_geodf.columns
[12]:
Index(['RMV Crash Number', 'City Town Name', 'Crash Date', 'Crash Time',
'Crash Severity', 'Maximum Injury Severity Reported',
'Number of Vehicles', 'Total Nonfatal Injuries', 'Total Fatal Injuries',
'Manner of Collision', 'Unnamed: 10', 'Vehicle Action Prior to Crash',
'Vehicle Travel Directions', 'Unnamed: 13', 'Unnamed: 14',
'Most Harmful Events', 'Vehicle Configuration',
'Road Surface Condition', 'Ambient Light', 'Weather Condition',
'At Roadway Intersection', 'Distance From Nearest Roadway Intersection',
'Distance From Nearest Milemarker', 'Distance From Nearest Exit',
'Distance From Nearest Landmark', 'Non Motorist Type', 'X Cooordinate',
'Y Cooordinate', 'geometry', 'severity'],
dtype='object')
[13]:
map_center = milton_boundaries.to_crs("EPSG:4326").loc[189].geometry.centroid
milton_map = folium.Map(width=800,height=800, location=[map_center.y, map_center.x], zoom_start=13)
for i, row in crash_geodf.to_crs("EPSG:4326").iterrows():
folium.CircleMarker(
(row.geometry.y, row.geometry.x),
radius=5,
color=colormap[row['severity']],
popup=folium.Popup(f"""
Crash Date: {row['Crash Date']}<br>
Crash Time: {row['Crash Time']}<br>
Weather Conditions: {row['Weather Condition']}<br>
Maximum Injury Severity Reported: {row['Maximum Injury Severity Reported']}
"""
)
).add_to(milton_map)
display(milton_map)
Make this Notebook Trusted to load map: File -> Trust Notebook
[14]:
crash_geodf.head()
[14]:
| RMV Crash Number | City Town Name | Crash Date | Crash Time | Crash Severity | Maximum Injury Severity Reported | Number of Vehicles | Total Nonfatal Injuries | Total Fatal Injuries | Manner of Collision | ... | At Roadway Intersection | Distance From Nearest Roadway Intersection | Distance From Nearest Milemarker | Distance From Nearest Exit | Distance From Nearest Landmark | Non Motorist Type | X Cooordinate | Y Cooordinate | geometry | severity | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 4136317 | MILTON | 01-Jan-2016 | 2:50 AM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | NaN | Rte 93 S / UNKNOWN | NaN | Exit 9 on Rte 93 S | NaN | NaN | 237954.181333 | 889568.707045 | POINT (237954.181 889568.707) | No Injury |
| 1 | 4138031 | MILTON | 03-Jan-2016 | 2:30 AM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | NaN | UNQUITY ROAD / HARLAND STREET | NaN | NaN | CAMP SAYRE | NaN | 233823.778861 | 887239.065913 | POINT (233823.779 887239.066) | No Injury |
| 2 | 4170301 | MILTON | 03-Jan-2016 | 3:08 AM | Property damage only (none injured) | No injury | 3.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | REEDSDALE ROAD / THOMPSON LANE | REEDSDALE ROAD / THOMPSON LANE | NaN | NaN | NaN | NaN | 234704.583122 | 889639.264997 | POINT (234704.583 889639.265) | No Injury |
| 3 | 4170346 | MILTON | 03-Jan-2016 | 11:28 AM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Rear-end | ... | NaN | 1249 RANDOLPH AVENUE Rte 28 | NaN | NaN | NaN | NaN | 235426.833031 | 886303.215857 | POINT (235426.833 886303.216) | No Injury |
| 4 | 4170384 | MILTON | 03-Jan-2016 | 6:47 PM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | NaN | 1043 RANDOLPH AVENUE | NaN | NaN | NaN | NaN | 235455.851915 | 887025.734960 | POINT (235455.852 887025.735) | No Injury |
5 rows × 30 columns
[15]:
crash_geodf['crash_time'] = pd.to_datetime(crash_geodf['Crash Date'] + " " + crash_geodf['Crash Time'])
[16]:
crash_geodf.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
Index: 4261 entries, 0 to 4568
Data columns (total 31 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 RMV Crash Number 4261 non-null object
1 City Town Name 4261 non-null object
2 Crash Date 4261 non-null object
3 Crash Time 4261 non-null object
4 Crash Severity 4261 non-null object
5 Maximum Injury Severity Reported 4261 non-null object
6 Number of Vehicles 4261 non-null float64
7 Total Nonfatal Injuries 4261 non-null float64
8 Total Fatal Injuries 4261 non-null float64
9 Manner of Collision 4261 non-null object
10 Unnamed: 10 0 non-null float64
11 Vehicle Action Prior to Crash 4260 non-null object
12 Vehicle Travel Directions 4260 non-null object
13 Unnamed: 13 0 non-null float64
14 Unnamed: 14 0 non-null float64
15 Most Harmful Events 4201 non-null object
16 Vehicle Configuration 4258 non-null object
17 Road Surface Condition 4224 non-null object
18 Ambient Light 4261 non-null object
19 Weather Condition 4261 non-null object
20 At Roadway Intersection 1062 non-null object
21 Distance From Nearest Roadway Intersection 4259 non-null object
22 Distance From Nearest Milemarker 215 non-null object
23 Distance From Nearest Exit 956 non-null object
24 Distance From Nearest Landmark 266 non-null object
25 Non Motorist Type 70 non-null object
26 X Cooordinate 4261 non-null float64
27 Y Cooordinate 4261 non-null float64
28 geometry 4261 non-null geometry
29 severity 4261 non-null object
30 crash_time 4261 non-null datetime64[ns]
dtypes: datetime64[ns](1), float64(8), geometry(1), object(21)
memory usage: 1.0+ MB
[17]:
roads_df = gpd.read_file("../data/raw/MassDOT_Roads_SHP/EOTMAJROADS_RTE_MAJOR.shp")
[18]:
ax = roads_df[roads_df.RT_NUMBER=="28"].plot()
ctx.add_basemap(ax, crs="EPSG:26986")
[19]:
rt28 = roads_df[roads_df.RT_NUMBER=="28"]
milton_rt_28 = gpd.clip(rt28, milton_boundaries)
ax = milton_rt_28.plot()
ctx.add_basemap(ax, crs="EPSG:26986")
[ ]:
[20]:
df_nearest_major_road = gpd.sjoin_nearest(crash_geodf, roads_df, how="left", distance_col="distance_to_major_road")
[21]:
df_nearest_major_road.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
Index: 7884 entries, 0 to 4568
Data columns (total 36 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 RMV Crash Number 7884 non-null object
1 City Town Name 7884 non-null object
2 Crash Date 7884 non-null object
3 Crash Time 7884 non-null object
4 Crash Severity 7884 non-null object
5 Maximum Injury Severity Reported 7884 non-null object
6 Number of Vehicles 7884 non-null float64
7 Total Nonfatal Injuries 7884 non-null float64
8 Total Fatal Injuries 7884 non-null float64
9 Manner of Collision 7884 non-null object
10 Unnamed: 10 0 non-null float64
11 Vehicle Action Prior to Crash 7881 non-null object
12 Vehicle Travel Directions 7881 non-null object
13 Unnamed: 13 0 non-null float64
14 Unnamed: 14 0 non-null float64
15 Most Harmful Events 7782 non-null object
16 Vehicle Configuration 7879 non-null object
17 Road Surface Condition 7825 non-null object
18 Ambient Light 7884 non-null object
19 Weather Condition 7884 non-null object
20 At Roadway Intersection 1632 non-null object
21 Distance From Nearest Roadway Intersection 7878 non-null object
22 Distance From Nearest Milemarker 593 non-null object
23 Distance From Nearest Exit 2460 non-null object
24 Distance From Nearest Landmark 554 non-null object
25 Non Motorist Type 104 non-null object
26 X Cooordinate 7884 non-null float64
27 Y Cooordinate 7884 non-null float64
28 geometry 7884 non-null geometry
29 severity 7884 non-null object
30 crash_time 7884 non-null datetime64[ns]
31 index_right 7884 non-null int64
32 ADMIN_TYPE 7884 non-null int64
33 RT_NUMBER 7884 non-null object
34 SHAPE_LEN 7884 non-null float64
35 distance_to_major_road 7884 non-null float64
dtypes: datetime64[ns](1), float64(10), geometry(1), int64(2), object(22)
memory usage: 2.2+ MB
[22]:
rt_28_crashes = df_nearest_major_road[(df_nearest_major_road.RT_NUMBER=="28") & (df_nearest_major_road.distance_to_major_road < 10.0)]
rt_28_crashes
[22]:
| RMV Crash Number | City Town Name | Crash Date | Crash Time | Crash Severity | Maximum Injury Severity Reported | Number of Vehicles | Total Nonfatal Injuries | Total Fatal Injuries | Manner of Collision | ... | X Cooordinate | Y Cooordinate | geometry | severity | crash_time | index_right | ADMIN_TYPE | RT_NUMBER | SHAPE_LEN | distance_to_major_road | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 4170301 | MILTON | 03-Jan-2016 | 3:08 AM | Property damage only (none injured) | No injury | 3.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | 234704.583122 | 889639.264997 | POINT (234704.583 889639.265) | No Injury | 2016-01-03 03:08:00 | 3 | 3 | 28 | 301154.96848 | 0.000124 |
| 3 | 4170346 | MILTON | 03-Jan-2016 | 11:28 AM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Rear-end | ... | 235426.833031 | 886303.215857 | POINT (235426.833 886303.216) | No Injury | 2016-01-03 11:28:00 | 3 | 3 | 28 | 301154.96848 | 0.000037 |
| 4 | 4170384 | MILTON | 03-Jan-2016 | 6:47 PM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | 235455.851915 | 887025.734960 | POINT (235455.852 887025.735) | No Injury | 2016-01-03 18:47:00 | 3 | 3 | 28 | 301154.96848 | 0.000186 |
| 6 | 4172349 | MILTON | 05-Jan-2016 | 12:02 AM | Property damage only (none injured) | No injury | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | 235553.115602 | 888768.223461 | POINT (235553.116 888768.223) | No Injury | 2016-01-05 00:02:00 | 3 | 3 | 28 | 301154.96848 | 0.049938 |
| 8 | 4172298 | MILTON | 05-Jan-2016 | 2:47 PM | Property damage only (none injured) | No injury | 2.0 | 0.0 | 0.0 | Sideswipe, same direction | ... | 233466.280912 | 890649.454822 | POINT (233466.281 890649.455) | No Injury | 2016-01-05 14:47:00 | 3 | 3 | 28 | 301154.96848 | 0.000412 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 4469 | 5138218 | MILTON | 03-Aug-2022 | 12:59 AM | Property damage only (none injured) | No Apparent Injury (O) | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | 233513.001100 | 890673.026900 | POINT (233513.001 890673.027) | No Injury | 2022-08-03 00:59:00 | 3 | 3 | 28 | 301154.96848 | 0.000959 |
| 4484 | 5154451 | MILTON | 11-Aug-2022 | 8:48 AM | Non-fatal injury | Suspected Minor Injury (B) | 2.0 | 0.0 | 0.0 | Angle | ... | 233608.430200 | 890315.144300 | POINT (233608.430 890315.144) | Minor Injury | 2022-08-11 08:48:00 | 3 | 3 | 28 | 301154.96848 | 0.000115 |
| 4506 | 5143294 | MILTON | 20-Aug-2022 | 4:31 PM | Property damage only (none injured) | No Apparent Injury (O) | 2.0 | 0.0 | 0.0 | Rear-end | ... | 233511.265594 | 890591.182415 | POINT (233511.266 890591.182) | No Injury | 2022-08-20 16:31:00 | 3 | 3 | 28 | 301154.96848 | 0.069996 |
| 4523 | 5144478 | MILTON | 30-Aug-2022 | 5:15 PM | Property damage only (none injured) | No Apparent Injury (O) | 2.0 | 0.0 | 0.0 | Angle | ... | 233520.676606 | 890363.794546 | POINT (233520.677 890363.795) | No Injury | 2022-08-30 17:15:00 | 3 | 3 | 28 | 301154.96848 | 0.030940 |
| 4544 | 5157351 | MILTON | 26-Sep-2022 | 1:11 AM | Property damage only (none injured) | No Apparent Injury (O) | 1.0 | 0.0 | 0.0 | Single vehicle crash | ... | 233466.281100 | 890649.455000 | POINT (233466.281 890649.455) | No Injury | 2022-09-26 01:11:00 | 3 | 3 | 28 | 301154.96848 | 0.000209 |
797 rows × 36 columns
[23]:
ax = rt_28_crashes.plot(column="severity")
ctx.add_basemap(ax, crs="EPSG:26986")
[24]:
rt_28_crashes['month_year'] = rt_28_crashes['crash_time'].dt.to_period('M')
/Users/alexhasha/Library/Caches/pypoetry/virtualenvs/milton-maps-gfMaDXEA-py3.10/lib/python3.10/site-packages/geopandas/geodataframe.py:1443: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
super().__setitem__(key, value)
[25]:
df = rt_28_crashes.groupby(["month_year", "severity"])['RMV Crash Number'].count().reset_index()
df
[25]:
| month_year | severity | RMV Crash Number | |
|---|---|---|---|
| 0 | 2016-01 | Minor Injury | 3 |
| 1 | 2016-01 | No Injury | 11 |
| 2 | 2016-01 | Unknown | 1 |
| 3 | 2016-02 | Minor Injury | 3 |
| 4 | 2016-02 | No Injury | 4 |
| ... | ... | ... | ... |
| 197 | 2022-07 | Minor Injury | 1 |
| 198 | 2022-07 | No Injury | 1 |
| 199 | 2022-08 | Minor Injury | 1 |
| 200 | 2022-08 | No Injury | 4 |
| 201 | 2022-09 | No Injury | 1 |
202 rows × 3 columns
[26]:
#df.columns
accidents_over_time = df.pivot(index='month_year', columns='severity', values='RMV Crash Number').fillna(0)
[27]:
accidents_over_time.plot.area()
[27]:
<Axes: xlabel='month_year'>
[28]:
milton_roads_df = gpd.read_file("../data/raw/MassDOT_Roads_SHP/EOTROADS_ARC.shp", mask=milton_boundaries)
ax = milton_roads_df.plot()
ctx.add_basemap(ax,crs="EPSG:26986")
[29]:
milton_roads_df.head()
[29]:
| STREETNAME | CLASS | ADMIN_TYPE | RT_NUMBER | ALTRTNUM1 | ALTRTNUM2 | ALTRTNUM3 | ALTRTNUM4 | ALTRT1TYPE | RDTYPE | ... | RPA | RTA | MILE_COUNT | AADT | AADT_YEAR | AADT_DERIV | LENGTH_MI | LENGTH_FT | SHAPE_LEN | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | PACELLA PARK DRIVE | 5 | 0 | NaN | NaN | NaN | NaN | NaN | 0 | 5 | ... | MAPC | MBTA | 0 | 0 | 0 | 0 | 0.035725 | 188.627991 | 57.493927 | LINESTRING (237063.940 883948.684, 237063.085 ... |
| 1 | ARLINGTON STREET | 5 | 0 | NaN | NaN | NaN | NaN | NaN | 0 | 5 | ... | MAPC | MBTA | 0 | 0 | 0 | 0 | 0.228811 | 1208.124179 | 368.236986 | LINESTRING (231106.734 890388.625, 231113.016 ... |
| 2 | HARLAND STREET | 5 | 0 | NaN | NaN | NaN | NaN | NaN | 0 | 5 | ... | MAPC | MBTA | 0 | 0 | 0 | 0 | 0.025421 | 134.223842 | 40.911509 | LINESTRING (233820.895 887395.682, 233830.778 ... |
| 3 | WOODMERE DRIVE | 5 | 0 | NaN | NaN | NaN | NaN | NaN | 0 | 5 | ... | MAPC | MBTA | 0 | 0 | 0 | 0 | 0.021975 | 116.026405 | 35.364919 | LINESTRING (231667.596 888062.852, 231666.406 ... |
| 4 | WOODMERE DRIVE | 5 | 0 | NaN | NaN | NaN | NaN | NaN | 0 | 5 | ... | MAPC | MBTA | 0 | 0 | 0 | 0 | 0.219525 | 1159.089475 | 353.291178 | LINESTRING (231638.570 888082.893, 231631.157 ... |
5 rows × 71 columns
[30]:
chickatawbut_road = milton_roads_df[milton_roads_df.STREETNAME=="CHICKATAWBUT ROAD"].dissolve()
chickatawbut_road.plot()
[30]:
<Axes: >
[31]:
chickatawbut_road.dissolve().plot()
[31]:
<Axes: >
[32]:
randolph_ave = milton_roads_df[milton_roads_df.STREETNAME=="RANDOLPH AVENUE"].dissolve()
randolph_ave.plot()
[32]:
<Axes: >
[33]:
pd.concat([randolph_ave, chickatawbut_road]).plot()
[33]:
<Axes: >
[34]:
randolph_chickatawbut_intsct = randolph_ave.geometry.intersection(chickatawbut_road.geometry).buffer(50)
ax = pd.concat([randolph_ave, chickatawbut_road]).plot()
ax = randolph_chickatawbut_intsct.plot(ax=ax)
ctx.add_basemap(ax, crs="EPSG:26986")
[35]:
ax = randolph_chickatawbut_intsct.plot()
ctx.add_basemap(ax, crs="EPSG:26986", zoom=12)
[36]:
randolph_chickatawbut_intsct
[36]:
0 POLYGON ((235493.881 886062.686, 235493.641 88...
dtype: geometry
[37]:
193.18/647
[37]:
0.29857805255023184
[ ]: